package com.example.xiaoyi.weiju.Overing;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.example.xiaoyi.weiju.Adapter.GuidePagerAdapter;
import com.example.xiaoyi.weiju.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/7/8.
 */
public class GudieActivity extends Activity {
    private ViewPager mviewpager;
    private List<View> mview;
    private int[] imageId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.guide);
        initView();
    }
    private void initView(){
        mviewpager=(ViewPager)findViewById(R.id.viewpager);
        imageId =new int[]{R.drawable.gudie,R.drawable.guide1,R.drawable.guide3};
        mview=new ArrayList<>();
        for(int i=0;i<imageId.length+1;i++){
            ImageView imageView = new ImageView(this);
            if(i!=imageId.length){
                imageView.setImageResource(imageId[i]);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            }
           final GuidePagerAdapter adapter = new GuidePagerAdapter(mview);
            mviewpager.setAdapter(adapter);
            mviewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                    if( position==adapter.getCount()-1){
                        startActivity(new Intent(GudieActivity.this,ActivityHome.class));
                        finish();
                        overridePendingTransition(R.anim.activity_enter,R.anim.activity_excit);
                    }
                }

                @Override
                public void onPageSelected(int position) {

                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });
        }
    }
}
